package com.zhuzhe.blog.question.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.zhuzhe.blog.base.ResponseData;
import com.zhuzhe.blog.question.entity.Question;
import com.zhuzhe.blog.question.requestDto.QuestionDto;
import com.zhuzhe.blog.question.requestDto.QuestionThumhupDto;
import com.zhuzhe.blog.question.requestDto.QuestionUserDto;
import com.zhuzhe.blog.question.responseVo.QuestionPageVo;
import com.zhuzhe.blog.question.service.IQuestionService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 问题信息表 前端控制器
 * </p>
 *
 * @author u53
 * @since 2020-10-08
 */
@Api(value = "问答管理接口", description = "问答管理接口, 提供问答的增删改查")
@RestController
@RequestMapping("/question")
public class QuestionController {
    @Autowired
    private IQuestionService questionService;

    @ApiOperation("修改问题信息接口")
    @PutMapping // put 方式请求 /question/question
    public ResponseData<String> update(@RequestBody QuestionDto questionDto) {
        return questionService.updateOrSave(questionDto);
    }

    @ApiOperation("新增问题信息接口")
    @PostMapping // post 请求 /question/question
    public ResponseData<String> save(@RequestBody QuestionDto questionDto) {
        return questionService.updateOrSave(questionDto);
    }

    @ApiOperation("删除问题信息接口")
    @ApiImplicitParam(name = "id", value = "问题ID", required = true)
    @DeleteMapping("/{id}")
    public ResponseData<String> delete(@PathVariable("id") String id) {
        return questionService.deleteById(id);
    }

    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "问题ID", required = true),
            @ApiImplicitParam(name = "count", value = "点赞数(只能是1或-1)", required = true)
    })
    @ApiOperation("更新点赞数")
    @PutMapping("/thumb/")
    public ResponseData<String> updateThumhup(@RequestBody QuestionThumhupDto questionThumhupDto) {
        return questionService.updateThumhup(questionThumhupDto);
    }

    @ApiOperation("根据用户id查询问题列表")
    @PostMapping("/user")
    public ResponseData<IPage<QuestionPageVo>> findListByUserId(@RequestBody QuestionUserDto questionUserDto) {
        return questionService.findListByUserId(questionUserDto);
    }

    @ApiOperation("查询提问总记录")
    @GetMapping("/total")  // /question/question/total
    public ResponseData<Integer> questionTotal() {
        return questionService.getQuestionTotal();
    }

    @ApiOperation("采纳问题")
    @PutMapping("/adoption/{id}/{replyid}")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "问题ID", required = true),
            @ApiImplicitParam(name = "replyid", value = "评论id 0未采纳 1采纳", required = true)
    })
    public ResponseData<String> adoptionQuetion(@PathVariable("id") String id,
                                                @PathVariable("replyid") String replyid) {
        return questionService.adoptionQuetion(id,replyid);
    }
}
